package com.dh.project.controller;

import com.dh.project.model.ClassService;
import com.dh.project.model.NewManage;
import com.dh.project.other.ModelRes;
import com.dh.project.service.ClassServiceService;
import com.dh.project.service.NewManageService;
import com.dh.project.service.ServiceProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2017/4/24.
 */
@Controller
public class NewsController {

    private NewManageService newManageService;

    private ServiceProjectService serviceProjectService;

    private ClassServiceService classServiceService;

    @Autowired
    public NewsController(NewManageService newManageService,ServiceProjectService serviceProjectService,
                          ClassServiceService classServiceService){
        this.newManageService = newManageService;
        this.serviceProjectService = serviceProjectService;
        this.classServiceService = classServiceService;
    }

    /**
     * 查询所有新闻信息
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectNews",produces = "text/html;charset=utf-8")
    public Object selectNews(){
        Map map = new HashMap();
        List<NewManage> newManages = newManageService.selectAllNewsManage(map);
        return new ModelRes(newManages);
    }

    /**
     * 查询新闻详情
     * @param news_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectNewsById",produces = "text/html;charset=utf-8")
    public Object selectNewsById(int news_id){
        NewManage newManage = newManageService.selectById(Long.valueOf(news_id));
        return new ModelRes(ModelRes.Status.SUCCESS,"查询成功",newManage);
    }

    /**
     * 查询服务项详情
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "selectClassServiceById",produces = "text/html;charset=utf-8")
    public Object selectServiceProject(int class_id){
        ClassService classService = classServiceService.selectById(Long.valueOf(class_id));
        return new ModelRes(ModelRes.Status.SUCCESS,"查询成功",classService);
    }

}
